package com.vben.ai.controller;

import com.vben.ai.service.ChatService;
import com.vben.common.core.util.R;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * ai相关模型调用
 *
 * @author sunnfun
 */
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private ChatService chatService;

    /**
     * ChatClient 简单调用
     */
    @GetMapping("/simple")
    public R<String> simpleChat(@RequestParam(value = "model", defaultValue = "qwen-max") String model, @RequestParam(value = "message", defaultValue = "你好，很高兴认识你，能简单介绍一下自己吗？") String message) {
        return R.ok(chatService.simple(model, message));
    }

    /**
     * ChatClient 流式调用
     */
    @GetMapping("/stream")
    public Flux<String> streamChat(@RequestParam(value = "model", defaultValue = "qwen-max") String model, @RequestParam(value = "message", defaultValue = "你好，很高兴认识你，能简单介绍一下自己吗？") String message, HttpServletResponse response) {
        response.setCharacterEncoding("UTF-8");
        return chatService.stream(model, message);
    }

}
